package pl.lsierant.j2me.bipacz.persistent;

import pl.lsierant.j2me.bipacz.intervaltimer.Interval;
import pl.lsierant.j2me.bipacz.intervaltimer.IntervalTimerDef;
import pl.lsierant.j2me.bipacz.notifications.impl.BeepNotification;
import pl.lsierant.j2me.bipacz.notifications.impl.DefaultNotification;
import pl.lsierant.j2me.bipacz.notifications.impl.FlashNotification;
import pl.lsierant.j2me.bipacz.notifications.impl.NullNotification;
import pl.lsierant.j2me.bipacz.notifications.impl.VibrateNotification;

public class PersistentObjectFactory {
    public static PersistentObjectFactory getInstance() {
        return new PersistentObjectFactory();
    }

    // use factory method - getInstance
    private PersistentObjectFactory() {
    }

    /**
     * Method creates persistent objects by type. Used due to slow Class.forName
     * method.
     * 
     * @param type
     *            persistent object type, e.g
     *            PersistentObjectType.BEEP_NOTIFICATION
     * @return uninitialized object instance
     */
    public IPersistent create(int type) {
        switch (type) {
        case PersistentObjectType.BEEP_NOTIFICATION:
            return new BeepNotification();
        case PersistentObjectType.DEFAULT_NOTIFICATION:
            return DefaultNotification.INSTANCE;
        case PersistentObjectType.FLASH_NOTIFICATION:
            return new FlashNotification();
        case PersistentObjectType.NULL_NOTIFICATION:
            return NullNotification.INSTANCE;
        case PersistentObjectType.VIBRATE_NOTIFICATION:
            return new VibrateNotification();
        case PersistentObjectType.INTERVAL_TIMER_DEF:
            return new IntervalTimerDef();
        case PersistentObjectType.INTERVAL:
            return new Interval();
        default:
            throw new PersistentException("Unknown persistent object type: " + type);
        }
    }
}
